import com.badlogic.gdx.ApplicationAdapter
import com.badlogic.gdx.Gdx
import com.badlogic.gdx.backends.lwjgl.LwjglApplication
import com.badlogic.gdx.graphics.Color
import com.badlogic.gdx.graphics.Texture
import com.badlogic.gdx.graphics.g2d.Sprite
import com.badlogic.gdx.graphics.g2d.SpriteBatch
import com.badlogic.gdx.graphics.g2d.TextureRegion

fun main(args: Array<String>)
{
    LwjglApplication(MainPage(), config {
        width = 480
        height = 320
        useGL20 = true
        backgroundFPS = 30
        foregroundFPS = 120
        initialBackgroundColor = Color.GRAY
        resizable = false
        title = "ImageRender"
    })
}

class MainPage : ApplicationAdapter()
{
    private val texture by lazy { Texture(Gdx.files.internal("aiweier.jpg")) }

    private val batch by lazy { SpriteBatch() }

    private val sprite by lazy { Sprite() }

    private val leftRegion by lazy {
        TextureRegion(texture, 0, 0, 512, 512)
    }
    private val rightRegion by lazy {
        TextureRegion(texture, 512, 0, 512, 512)
    }

    override fun create()
    {
        sprite.setRegion(rightRegion)
        sprite.setSize(120f, 120f)
        sprite.setOrigin(20f, 20f)
        sprite.rotation = 50f
        sprite.setPosition(100f, 100f)
        sprite.setColor(1f, 0f, 1f, 1f)
    }

    override fun render()
    {
        clear()
        batch.begin()
        
        sprite.draw(batch)

        //batch.draw(texture, 0f, 0f, Gdx.graphics.floatWidth, Gdx.graphics.floatHeight)
        //batch.draw(leftRegion, 0f, 0f, Gdx.graphics.floatWidth, Gdx.graphics.floatHeight)


        batch.end()
    }

    override fun dispose()
    {
        texture.dispose()
        batch.dispose()
    }

}